package com.goertek.easyface.device;

import com.netsdk.module.LoginModule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

/**
 * @program: easy-face
 * @description:
 * @author: devin.duj
 * @create: 2024-03-29 13:11
 */
@Component
@Slf4j
public class ShutdownListener implements ApplicationListener<ContextClosedEvent> {
    @Autowired
    private DeviceStore deviceStore;
    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        log.info("程序关闭回调");
        try{
            deviceStore.stopBatch(); //登出+取消订阅
        }finally {
        }
        LoginModule.cleanup();   // 关闭工程，释放资源
        log.info("JNA资源已释放");
    }
}